package com.ruoyi.personnel.controller;

import java.math.BigDecimal;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Date;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.personnel.domain.EPersonnel;
import com.ruoyi.personnel.service.IEPersonnelService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 会员管理Controller
 *
 * @author ruoyi
 * @date 2024-11-21
 */
@CrossOrigin
@Slf4j
@RestController
@RequestMapping("/courier")
public class EPersonnelController extends BaseController
{
    @Autowired
    private IEPersonnelService ePersonnelService;

    /**
     * 查询快递员管理列表
     */
    @RequiresPermissions("personnel:courier:list")
    @GetMapping("/courierList")
    public TableDataInfo courierList(EPersonnel ePersonnel)
    {
        startPage();
        List<EPersonnel> list = ePersonnelService.selectCourierList(ePersonnel);
        return getDataTable(list);
    }

    /**
     * 查询普通会员管理列表
     */
    @RequiresPermissions("personnel:member:list")
    @GetMapping("/memberList")
    public TableDataInfo list(EPersonnel ePersonnel)
    {
        startPage();
        List<EPersonnel> list = ePersonnelService.selectMemberList(ePersonnel);
        return getDataTable(list);
    }

    /**
     * 导出会员管理列表
     */
    @RequiresPermissions("personnel:courier:export")
    @Log(title = "会员管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EPersonnel ePersonnel)
    {
        List<EPersonnel> list = ePersonnelService.selectCourierList(ePersonnel);
        ExcelUtil<EPersonnel> util = new ExcelUtil<EPersonnel>(EPersonnel.class);
        util.exportExcel(response, list, "会员管理数据");
    }

    /**
     * 获取会员管理详细信息
     */

    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(ePersonnelService.selectEPersonnelById(id));
    }

    /**
     * 新增会员管理
     */
    @RequiresPermissions("personnel:courier:add")
    @Log(title = "会员管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EPersonnel ePersonnel)
    {
        return success(ePersonnelService.insertAndGetResult(ePersonnel));
    }

    /**
     * 修改会员管理
     */
    @RequiresPermissions("personnel:courier:edit")
    @Log(title = "会员管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EPersonnel ePersonnel)
    {
        return toAjax(ePersonnelService.updateEPersonnel(ePersonnel));
    }

    /**
     * 删除会员管理
     */
    @RequiresPermissions("personnel:courier:remove")
    @Log(title = "会员管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ePersonnelService.deleteEPersonnelByIds(ids));
    }


    /*
    * 重置登录密码
    * */
    @PutMapping("resetLoginPassword/{lid}")
    public AjaxResult resetLoginPassword(@PathVariable("lid")Long lid){
    	return success(ePersonnelService.resetLoginPassword(lid));
    }

    /*
    * 置空支付密码
    * */
    @PutMapping("resetPaymentPassword/{lid}")
    public AjaxResult resetPaymentPassword(@PathVariable("lid")Long lid){
    	return success(ePersonnelService.resetPaymentPassword(lid));
    }

    /*
    * 改变当前的状态
    * */
    @PutMapping("updateStatus")
    public AjaxResult updateStatus(@RequestBody EPersonnel ePersonnel){
        return toAjax(ePersonnelService.updateStatus(ePersonnel));
    }
}
